package com.yoyo.itravel.dao;


import com.yoyo.itravel.bean.Role;
import com.yoyo.itravel.bean.Sight;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

/**
 * @Description 角色数据操作持久层接口
 *
 * @author CRR
 * @date 2020/6/22 11:26
 */
@Repository
public interface IRoleDao {

    /**
     * @Description 添加角色
     *
     * @param role
     * @return int
     */
    @Insert("insert into tb_role values(#{roleId},#{roleName},#{description})")
    int insert(Role role) throws SQLException;

    /**
     * @Description 通过id删除角色
     * @return int
     * @param roleId
     */
    @Delete("delete from tb_role where roleId=#{roleId}")
    int deleteByRoleId(String roleId) throws SQLException;
    /**
     * @Description 通过角色名查找角色
     *
     * @param roleName
     * @return cn.hut.travel.bean.Role
     */
    @Select("select * from tb_role where roleName=#{roleName}")
    Role selectByRoleName(String roleName) throws SQLException;

    /**
     * @Description 通过角色名查找角色id
     *
     * @param roleName
     * @return cn.hut.travel.bean.Role
     */
    @Select("select roleId from tb_role where roleName=#{roleName}")
    String selectRoleIdByRoleName(String roleName) throws SQLException;

    /**
     * @Description 通过角色id查找角色
     *
     * @param roleId
     * @return cn.hut.travel.bean.Role
     */
    @Select("select * from tb_role where roleId=#{roleId}")
    Role selectByRoleId(String roleId) throws SQLException;

    /**
     * @Description 通过用户id查找用户的角色
     *
     * @param userId
     * @return java.util.List<cn.hut.travel.bean.Role>
     */
    @Select("select * from tb_role where roleId in (select roleId from middle_tb_user_role where userId=#{roleId})")
    List<Role> selectAllByUserId(String userId) throws SQLException;

     /**
     *@Description: 分页查询所有角色
     *@param:start
     *@param:pageSize
     *@return java.util.List<cn.hut.travel.bean.Role>
     */
     @Select("select * from tb_role limit #{start}, #{pageSize}")
     List<Role> selectAllByPage(@Param("start") int start, @Param("pageSize") int pageSize) throws SQLException;

    /**
     * @Description 查询角色记录的总条数
     * @return int
     */
    @Select("select count(*) from tb_role")
    int selectTotalCount() throws SQLException;

}
